package test;

import com.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author libo
 * @version 1.0
 * @date 2018/5/16 17:27
 */
public class FileLoad {

    public static void load(){
        InputStream is = null;
        ByteArrayOutputStream bos  =null;
        try {
            bos = new ByteArrayOutputStream();
            System.out.println(FileLoad.class.getClassLoader());
            System.out.println(FileLoad.class.getClassLoader().getResource("test.properties"));
            is = FileLoad.class.getClassLoader().getResourceAsStream("test.properties");
            byte[] bytes = new byte[1024];
            int length;
            while ((length = is.read(bytes) )!= -1) {
                bos.write(bytes,0,length);
            }
            System.out.println(bos.toString("UTF-8"));
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (bos != null) {
                    try {
                        bos.flush();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    try {
                        bos.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
